#/bin/bash
export PATH=$PATH:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/java/latest/bin:/usr/java/latest/jre:/root/bin

Current=`date +"%F %H:%M:00"`
TimeStamp=`date -d "$Current" +%s`"000"
TimeStamp1=`expr $TimeStamp - 300000`
FileStamp=`date +%s`
FileName=AuthenticationLog_${FileStamp}.json
FileNameMd5=${FileName}_md5
mongoexport -h localhost:60003  -d Radius -c AuthenticationLog --slaveOk -q "{time : {\$gte : new Date($TimeStamp1) , \$lt :  new Date($TimeStamp)}}" -o /tmp/${FileName} -u izh -p izh-qwer

cd /tmp
find /tmp -type f -mmin +60 -name 'AuthenticationLog_*json' | xargs -i rm -rf {}
find /tmp -type f -mmin +60 -name 'AuthenticationLog_*md5' | xargs -i rm -rf {}
md5sum /tmp/${FileName} > /tmp/${FileNameMd5}


HOST=132.109.64.11
PORT=21001
FTP_USERNAME=vsftpd-yh
FTP_PASSWORD="]Yh-1631-Wifi["
FtpFile=${FileName}
FtpFileMd5=${FileNameMd5}
ftp -i -n -v << !
open ${HOST} ${PORT}
user ${FTP_USERNAME} ${FTP_PASSWORD}
bin
put ${FtpFile} 
put ${FtpFileMd5}
bye
!                                                                               

